<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class NewsCommentController extends AdminbaseController{
	protected $news_comment_model;
	protected $news_model;
	
	function _initialize() {
		parent::_initialize();
		$this->news_comment_model = D("Common/NewsComment");
		$this->news_model = D("Common/News");
	}
	
	function index(){
// 	    $newsId = I("param.newsId",0);
// 		$trtotal = $this->curl_http(C('news_url').'comments/getCommentList?token='.$_SESSION["TOKEN"].'&newsId='.$newsId.'&curPage=1&pageSize=1');
// 		$page = $this->page($trtotal['ReturnData']['page']['totalCount'],20);
// 		$result = $this->curl_http(C('news_url').'comments/getCommentList?token='.$_SESSION["TOKEN"]."&newsId='.$newsId.'&curPage=".$page->Current_page."&pageSize=".$page->Page_size);
// 		$this->assign("data", $result['ReturnData']['data']);
// 		$this->assign("page", $page->show('Admin')); 
// 		$this->display();
		$news_id = I('news_id','10');
		if($news_id){
			$news_info = $this->news_model->find($news_id);
			$this->assign('news_info',$news_info);
		}
		$formParam['keyword'] = I('param.keyword', '');
		$formParam['startDate'] = I('param.startDate', '');
		$formParam['endDate'] = I('param.endDate', '');
		
		$this->assign("formParam", $formParam);
		
		$currentPage = I('param.p', 0);
		if ($currentPage <= 0) {
			$currentPage = 1;
		}
		
		$pageSize = '20';
		$pageStart = ($currentPage - 1) * $pageSize;
		$pageEnd = $currentPage * $pageSize;
		$result = $this->news_comment_model->getNewsCommentList($formParam,$news_id,$pageStart,$pageSize);

		//分页
		$page = $this->page($result['count_Total'], 20);
		$this->assign("page", $page->show('Admin'));
		
		
		$this->assign("count_data", $count_data);
		$this->assign("data", $result['data']);
		$this->display();
	}

	function del(){
	    $commentId = I("param.commentId",0);
	    $news_id = I("param.news_id",0);
	    if(!$commentId || !$news_id){
	    	return $this->error("参数错误");
	    }
	    $data['status'] = '0';
// 	    $result = $this->curl_http(C('news_url').'comments/delComment?token='.$_SESSION["TOKEN"],'commentIds='.$commentIds);
	    if($this->news_comment_model->where('comment_id = '.$commentId)->data($data)->save()){
	        $this->success("删除成功！", U("Admin/NewsComment/index",array('news_id'=>$news_id)));
	    }else{
	        return $this->error($result['Message']);
	    }
	}
	
}